package cn.myschool.myschool.service;

import cn.myschool.myschool.entity.Student;
import cn.myschool.myschool.mapper.StudentMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
public class StudentService extends ServiceImpl<StudentMapper, Student> implements IStudentService {
    @Override
    public Page<Student> search(int pageNo, int pageSize, String sname, String qq, String tel, Date start, Date end) {
        QueryWrapper<Student> q=new QueryWrapper();
        q.select("stuno","sname","qq","enterdate");
        q.like(!StringUtils.isEmpty(sname),"sname",sname);
        q.like(!StringUtils.isEmpty(qq),"qq",qq);
        q.like(!StringUtils.isEmpty(tel),"telephone",tel);
        q.ge(!StringUtils.isEmpty(start),"enterdate",start);
        q.le(!StringUtils.isEmpty(end),"enterdate",end);
        q.orderByDesc("stuno");
        //return super.baseMapper.selectPage( Page.of(pageNo,pageSize),q);
        return super.page( Page.of(pageNo,pageSize),q);
    }
    //gradid统计人数
    public List gradeidGroup(){
        QueryWrapper q=new QueryWrapper();
        q.groupBy("gradeid");
        q.select("count(1) as renshu","gradeid");
        List list = super.listMaps(q);

        return list;
    }
}
